package org.lgl.goods.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.lgl.common.result.Result;
import org.lgl.goods.model.Brand;
import org.lgl.goods.service.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @date 2022/2/25 14:25
 */
@Api(tags = "Brand Module")
@RestController
@RequestMapping("/brand")
public class BrandController {
    private final BrandService brandService;

    public BrandController(BrandService brandService) {
        this.brandService = brandService;
    }

    @ApiOperation(value = "通过 id 查询 Brand")
    @GetMapping("/{id}")
    public Result<Brand> getById(@PathVariable("id") Long id) {
        return Result.success(brandService.getById(id));
    }

    @ApiOperation(value = "查询符合条件的 Brand")
    @PostMapping("/search")
    public Result<List<Brand>> searchList(@RequestBody Brand brand) {
        return Result.success(brandService.searchList(brand));
    }

    @ApiOperation(value = "分页查询 Brand")
    @GetMapping("/search/{pageIndex}/{pageSize}")
    public Result<PageInfo<Brand>> listWithPage(@PathVariable("pageIndex") Integer pageIndex
            , @PathVariable("pageSize") Integer pageSize) {
        return Result.success(brandService.listWithPage(pageIndex, pageSize));
    }
}
